import threading

import keyboard

output_mod = False


class Keyboard:
    event = None

    renew_thread = None

    def start(self):
        keyboard.hook(self.renew_event)
        if self.renew_thread is None:
            self.renew_thread = threading.Thread(target=self.start_input)
        self.renew_thread.start()

    def renew_event(self, e):
        self.event = e
        if output_mod:
            print(e)

    def start_input(self):
        keyboard.wait()

    a = 0

    def print_a(self):
        while True:
            self.check_a()
            print(self.a)

    def start_print_a(self):
        pa_Thread = threading.Thread(target=self.print_a)
        pa_Thread.start()

    def check_a(self):
        if self.event is not None:
            if self.event.event_type == 'down' and self.event.name == 'a':
                self.a = 1
            elif self.event.event_type == 'up' and self.event.name == 'a':
                self.a = 0


if __name__ == '__main__':
    k = Keyboard()
    k.start_print_a()
    k.start()
    k.renew_thread.join()
